package com.example.yuejian23.yuejian_23.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.yuejian23.yuejian_23.Data.Mdata;
import com.example.yuejian23.yuejian_23.R;
import com.example.yuejian23.yuejian_23.javaBean.FatieBean;
import com.example.yuejian23.yuejian_23.javaBean.PingjiaBean;
import com.example.yuejian23.yuejian_23.model.FatieModel;
import com.example.yuejian23.yuejian_23.model.PinglunModel;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class PingjiaActivity extends AppCompatActivity {
    private EditText neirong;
    private Button pingjia;
    String pid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pingjia);

        Bundle bundle = this.getIntent().getExtras();
        pid = bundle.getString("shaituid");

        initView();
        initEvents();
    }

    private void initView() {
        neirong = (EditText) findViewById(R.id.neirong);
        pingjia = (Button) findViewById(R.id.pingjia);
    }

    private void initEvents() {
        pingjia.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String nei = neirong.getText().toString();
                if(!nei.equals("")){

                        PinglunModel pinglunModel=new PinglunModel();
                        Call call=pinglunModel.pinglun(Mdata.uid,pid,nei);
                        Callback<PingjiaBean> callback = new Callback<PingjiaBean>() {
                            @Override
                            public void onResponse(Call<PingjiaBean> call, Response<PingjiaBean> response) {
                                //String userid = String.valueOf(response.body().getCode());
                                int code = response.body().getCode();
                                if(code == 0)
                                {
                                    Toast.makeText(PingjiaActivity.this,"评论失败",Toast.LENGTH_SHORT).show();
                                    //失败处理
                                }else
                                {

                                    Toast.makeText(PingjiaActivity.this,"评论成功",Toast.LENGTH_SHORT).show();
                                    finish();
                                    //成功处理
                                }
                            }

                            @Override
                            public void onFailure(Call<PingjiaBean> call, Throwable t) {

                            }
                        };
                        call.enqueue(callback);
                    }

                else {
                    Toast.makeText(PingjiaActivity.this,"请输入内容",Toast.LENGTH_SHORT).show();

                }

            }
        });
    }
}
